# Contributor: Mike Crute <mike@crute.us>
# Maintainer: Mike Crute <mike@crute.us>
pkgname=gortr
pkgver=0.14.8
pkgrel=8
pkgdesc="The RPKI-to-Router server used at Cloudflare"
url="https://rpki.cloudflare.com/"
arch="all"
license="BSD-3-Clause"
options="net chmod-clean"
makedepends="go"
pkgusers="gortr"
pkggroups="gortr"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/cloudflare/gortr/archive/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	make \
		OUTPUT_GORTR=dist/gortr \
		OUTPUT_RTRDUMP=dist/rtrdump \
		OUTPUT_RTRMON=dist/rtrmon \
		build-gortr build-rtrdump build-rtrmon
}

check() {
	make test
}

package() {
	install -Dm755 dist/gortr "$pkgdir"/usr/bin/$pkgname
	install -Dm755 dist/rtrdump "$pkgdir"/usr/bin/rtrdump
	install -Dm755 dist/rtrmon "$pkgdir"/usr/bin/rtrmon

	# Install RPKI root certificate, required to validate RPKI signed routes.
	# This is vended by CloudFlare but extracted from the RPKI.
	install -Dm644 cmd/gortr/cf.pub "$pkgdir"/usr/share/$pkgname/cf.pub

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
2d1793948783c40f4156f35e7b0ceb7422a09fe2d23f5d12373c8d3442688530329e1552c35ce63f6aef3b31efba10737095fde1e35e2bbb8a08fe4cbc1c311e  gortr-0.14.8.tar.gz
62142d3faa1cb34b39c1e1eb9698feb81dc7c53b3b0db9607b0c8cc10f3b20affc45525641e70fbc0aa0515abd02a48fe7a8a05ea809315ad90f5e139df39801  gortr.initd
06d5a49b90584a53ed879c12fab2d5a6d3ca0c3d35cd71e2d213b1513bb5335c3f107fabdacb0ff29f301a51e875fb5358076cdc4a366d3e400b6910bfde1ec6  gortr.confd
"
